package com.ztl.mymqtt.mqtt;

import android.content.Context;
import android.content.SharedPreferences;

public class MyMqttParasManager {

    public  static  void saveConfig(Context context,MyMqttParas parameters)
    {
        SharedPreferences.Editor editor=context.getSharedPreferences("MyMqttParas",Context.MODE_PRIVATE).edit();
        editor.putString("serverIp", parameters.serverIp);
        editor.putString("port", parameters.port);
        editor.putString("clientId", parameters.clientId);
        editor.putString("userName", parameters.userName);
        editor.putString("passWord", parameters.passWord);
        editor.putString("topicSub",parameters.topicSub);
        editor.apply();
    }

    public  static  MyMqttParas readConfig(Context context)
    {
        SharedPreferences preferences=context.getSharedPreferences("MyMqttParas",Context.MODE_PRIVATE);
        return new MyMqttParas(preferences.getString("serverIp", "192.168.1.101")
                , preferences.getString("port", "1883")
                , preferences.getString("clientId", "clientAndroid")
                , preferences.getString("userName", "")
                , preferences.getString("passWord", "")
        ,preferences.getString("topicSub","topicSub"));

    }
}
